package com.kgc.scd.config;

import com.kgc.scd.constant.SeckillConstant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created On : 2022/11/10.
 * <p>
 * Author : asus
 * <p>
 * Description: RabbitMQSeckillConfig
 */
@Configuration
public class RabbitMQSeckillConfig {

    @Bean
    public Queue directQueue(){
        return new Queue(SeckillConstant.SECKILL_SAVE_ORDER_QUEUE,true);
    }

    @Bean
    public DirectExchange directExchange(){
        // 创建持久化的直连交换机,要指定交换机的名称
        return new DirectExchange(SeckillConstant.SECKILL_SAVE_ORDER_EXCHANGE);
    }

    @Bean
    public Binding directBinding(){
        // 将直连队列和直连交换机绑定,并指定路由键
        return BindingBuilder.bind(directQueue()).to(directExchange()).with(SeckillConstant.SECKILL_SAVE_ORDER_BINDING);
    }
}
